/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Subjects {
    public static boolean insertSubject(Entity.Subject sbj){
        try {
            String sql = "insert into tblSubjects values(?,?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, sbj.get_SubID());
            ps.setString(2, sbj.get_SubName());
            ps.setInt(3, sbj.get_Hours());
            ps.setString(4, sbj.get_Description());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Subjects.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }        
    }
    
    public static boolean updateSubject(Entity.Subject sbj){
        try {
            String sql = "update tblSubjects set SubName=?, Hours=?, Description=? where SubID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, sbj.get_SubName());
            ps.setInt(2, sbj.get_Hours());
            ps.setString(3, sbj.get_Description());
            ps.setString(4, sbj.get_SubID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Subjects.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        
    }
    
    public static void deleteSubject(String strSubjectID){
        try {
            String sql = "delete from tblSubjects where SubID = '" + strSubjectID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Subjects.class.getName()).log(Level.SEVERE, null, ex);
        }
    }



}
